package com.marmot.cloud.framework.orm.jpa.entity;


import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.Transient;
import lombok.Data;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;

@Data
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseEntity {

    /** 查询指定区间时间 - 字段名*/
    @Transient
    protected String queryDateTimeField;
    /** 查询指定区间时间 - 开始时间*/
    @Transient
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    protected LocalDateTime queryDateTimeStart;
    /** 查询指定区间时间 - 结束时间*/
    @Transient
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    protected LocalDateTime queryDateTimeEnd;


    public String toJson() {
        return JSONUtil.toJsonStr(this);
    }
}
